package com.ruoyi.xdata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xdata.domain.XdataDatasource;
import com.ruoyi.xdata.service.IXdataDatasourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据源Controller
 * 
 * @author yepanpan
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/xdata/datasource")
public class XdataDatasourceController extends BaseController
{
    @Autowired
    private IXdataDatasourceService xdataDatasourceService;

    /**
     * 查询数据源列表
     */
    @GetMapping("/select")
    public TableDataInfo select(XdataDatasource xdataDatasource)
    {
        List<XdataDatasource> list = xdataDatasourceService.selectXdataDatasourceList(xdataDatasource);
        return getDataTable(list);
    }

    /**
     * 查询数据源列表
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:list')")
    @GetMapping("/list")
    public TableDataInfo list(XdataDatasource xdataDatasource)
    {
        startPage();
        List<XdataDatasource> list = xdataDatasourceService.selectXdataDatasourceList(xdataDatasource);
        return getDataTable(list);
    }

    /**
     * 导出数据源列表
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:export')")
    @Log(title = "数据源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XdataDatasource xdataDatasource)
    {
        List<XdataDatasource> list = xdataDatasourceService.selectXdataDatasourceList(xdataDatasource);
        ExcelUtil<XdataDatasource> util = new ExcelUtil<XdataDatasource>(XdataDatasource.class);
        util.exportExcel(response, list, "数据源数据");
    }


    /**
     * 获取数据源详细信息
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xdataDatasourceService.selectXdataDatasourceById(id));
    }

    /**
     * 新增数据源
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:add')")
    @Log(title = "数据源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody XdataDatasource xdataDatasource)
    {
        return toAjax(xdataDatasourceService.insertXdataDatasource(xdataDatasource));
    }

    /**
     * 修改数据源
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:edit')")
    @Log(title = "数据源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody XdataDatasource xdataDatasource)
    {
        return toAjax(xdataDatasourceService.updateXdataDatasource(xdataDatasource));
    }

    /**
     * 删除数据源
     */
    @PreAuthorize("@ss.hasPermi('xdata:datasource:remove')")
    @Log(title = "数据源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xdataDatasourceService.deleteXdataDatasourceByIds(ids));
    }
}
